<?php

namespace Common\Model;

use Think\Model;

class PatientModel extends Model {

    protected $tableName = 'patient';

    protected $_validate = array(
        ['sex', 'number', '性别选择有误，1男，2女'],
    );

    protected $_auto = array(
        ['create_time', 'time', self::MODEL_INSERT, 'function'],
        ['name', 'getName', self::MODEL_INSERT, 'callback'],
        ['sex', 'getSex', self::MODEL_INSERT, 'callback'],
    );

    /**
     * 获取名称
     */
    public function getName($name) {
        if ($name == '' || empty($name)) {
            return '无名氏';
        }

        return $name;
    }

    public function getSex($sex) {
        if ($sex == '' || empty($sex)) {
            return 0;
        }

        return $sex;
    }

    /**
     * 获取指定的病人id
     */
    public function getPatientInfo($patient_id) {
        $info = $this->where(['id' => $patient_id])->find();
        //TODO::  数据处理
        foreach ($info as &$value) {
            if (empty($value)) {
                $value = '';
            }
        }

        return $info;
    }

}